package cn.org.timespace.easyframe.util.sms;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Ping {
	

	public String ping(String ip) throws IOException {
		String str = "";
		String result = "";
		int index = 0;
		String   command= "ping  "+ip; 
		Process   process   =   Runtime.getRuntime().exec(command); 
		BufferedReader   bufferedreader   =   new   BufferedReader(new   InputStreamReader(process.getInputStream())); 
		String   line   =   bufferedreader.readLine(); 
		for(;line   !=   null;)   { 
			String   nextLine   =   bufferedreader.readLine(); 
			//�ڴ˴����õ�ping��!��Ϣ�������±ߵĴ�ӡ 
			//System.out.println(+line); 
			line   =   nextLine; 
			index++;
			while(index == 18){//��ȡPackets: Sent = ?, Received = ?, Lost = ? (100% loss),��һ����Ϣ����18����Ϣ��
				str = line.trim();
				int a = str.indexOf("(");
				int b = str.indexOf("%");
				result = str.substring(a+1, b);//result = 0��ʾ��;result = 25��ʾæµ;result = 50��75��ʾ�쳣;result = 100��ʾ�Ͽ�					
				break;
			}
		} 
		bufferedreader.close(); 
		return result;
	}
}